import sm3 from 'sm-crypto'
import {LogCat} from '../utils/logcat.js'

export default {

  sm3ApiSign: function (param) {
    LogCat.d("sm3ApiSign",param)
    return sm3.sm3(param.appSecretValue + this.getsigbody(param.appKeyvalue, param.uuid, param.timestamp))
  },
  getsigbody: function (appKeyvalue, uuid, timestamp) {
    LogCat.d("getsigbody",{appKeyvalue, uuid, timestamp})
    return "x-aep-appkey=" + appKeyvalue + "&x-aep-nonce=" + uuid + "&x-aep-timestamp=" + timestamp;
  },
  generateUUID: function () {
    LogCat.d("generateUUID","aaa")
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
      var r = Math.random() * 16 | 0,
          v = c == 'x' ? r : (r & 0x3 | 0x8);
      return v.toString(16);
    });
  }


}
